import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  build: {
    outDir: 'dist',
    lib: {
      entry: path.resolve(__dirname, './packages/components/index.js'),
      name: 'TestUI',
      fileName: (format) => `index.${format}.js`,
      formats: ['es', 'cjs', 'umd']
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        exports: 'named',
        globals: { vue: 'Vue' },
        // 关键配置：静态资源输出规则
        assetFileNames: (assetInfo) => {
          if (/\.(woff2?|eot|ttf|otf)$/.test(assetInfo.name)) {
            return 'theme-chalk/fonts/[name][extname]' // 保持原路径结构
          }
          if (/\.css$/.test(assetInfo.name)) {
            return 'theme-chalk/[name][extname]'
          }
          return 'assets/[name][extname]'
        }
      }
    },
    // 关键配置：强制包含字体文件
    assetsInclude: [
      '**/*.woff',
      '**/*.woff2',
      '**/*.eot',
      '**/*.ttf',
      '**/*.otf'
    ]
  }
})
